/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package entities;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import vo.VOKeyWord;

/**
 *
 * @author santiagobaldrich
 */
@Entity
@Table(name = "KeyWord")
@NamedQueries(
{
    @NamedQuery(name = "KeyWord.findAll", query = "SELECT k FROM KeyWord k"),
    @NamedQuery(name = "KeyWord.findByIdKeyWord", query = "SELECT k FROM KeyWord k WHERE k.idKeyWord = :idKeyWord"),
    @NamedQuery(name = "KeyWord.findByName", query = "SELECT k FROM KeyWord k WHERE k.name = :name")
})
public class KeyWord implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "idKeyWord")
    private Integer idKeyWord;
    @Basic(optional = false)
    @Column(name = "name")
    private String name;
    @JoinTable(name = "ProblemKeyword", joinColumns =
    {
        @JoinColumn(name = "idKeyWord", referencedColumnName = "idKeyWord")
    }, inverseJoinColumns =
    {
        @JoinColumn(name = "idProblem", referencedColumnName = "idProblem")
    })
    @ManyToMany
    private Collection<Problem> problemCollection;

    public KeyWord()
    {
    }

    public KeyWord(Integer idKeyWord)
    {
        this.idKeyWord = idKeyWord;
    }

    public KeyWord(Integer idKeyWord, String name)
    {
        this.idKeyWord = idKeyWord;
        this.name = name;
    }

    public Integer getIdKeyWord()
    {
        return idKeyWord;
    }

    public void setIdKeyWord(Integer idKeyWord)
    {
        this.idKeyWord = idKeyWord;
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public Collection<Problem> getProblemCollection()
    {
        return problemCollection;
    }

    public void setProblemCollection(Collection<Problem> problemCollection)
    {
        this.problemCollection = problemCollection;
    }

    @Override
    public int hashCode()
    {
        int hash = 0;
        hash += (idKeyWord != null ? idKeyWord.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object)
    {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof KeyWord))
        {
            return false;
        }
        KeyWord other = (KeyWord) object;
        if ((this.idKeyWord == null && other.idKeyWord != null) || (this.idKeyWord != null && !this.idKeyWord.equals(other.idKeyWord)))
        {
            return false;
        }
        return true;
    }

    @Override
    public String toString()
    {
        return "entities.KeyWord[idKeyWord=" + idKeyWord + "]";
    }
    public VOKeyWord getVO()
    {
        VOKeyWord vo = new VOKeyWord();
        vo.setIdKeyWord(idKeyWord);
        vo.setName(name);
        return vo;
    }
}
